package com.example.dsd.heimachengxuyuan.p62.d27;

import android.content.Context;
import android.content.SharedPreferences;
import android.os.Bundle;
import android.support.v7.app.AppCompatActivity;
import android.view.View;
import android.widget.CheckBox;
import android.widget.RelativeLayout;
import android.widget.SeekBar;

import com.example.dsd.heimachengxuyuan.R;

import butterknife.Bind;
import butterknife.ButterKnife;
import butterknife.OnClick;

public class Simulation_SystemSetting extends AppCompatActivity {

    @Bind(R.id.chkAutoFlip)
    CheckBox chkAutoFlip;
    @Bind(R.id.skbShowTempe)
    SeekBar sekShowTempe;
    @Bind(R.id.relative_SystemSetting)
    RelativeLayout relativeSystemSetting;

    private static SharedPreferences sp;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_simulation__system_setting);
        ButterKnife.bind(this);

        sp = getSharedPreferences("config", Context.MODE_PRIVATE);
        boolean isChekedStatus = sp.getBoolean("isChecked", false);
        chkAutoFlip.setChecked(isChekedStatus);
        int progressStatus = sp.getInt("progress",0);
        sekShowTempe.setProgress(progressStatus);


    }

    @OnClick({R.id.chkAutoFlip, R.id.skbShowTempe,
            R.id.relative_SystemSetting, R.id.txtAutoFlip})
    public void onClick(View view) {
        switch (view.getId()) {

            case R.id.relative_SystemSetting:
            case R.id.textView:
            case R.id.chkAutoFlip:
                //如果被勾选
                if (chkAutoFlip.isChecked()) {

                    SharedPreferences.Editor editor = sp.edit();
                    editor.putBoolean("isChecked", isChild());
                    editor.commit();
                }

                break;
            case R.id.skbShowTempe:
                new SeekBar.OnSeekBarChangeListener() {


                    //seekbar 的进度改变了   ----在拖动中
                    @Override
                    public void onProgressChanged(SeekBar seekBar, int progress, boolean fromUser) {

                    }

                    //开始拖动
                    @Override
                    public void onStartTrackingTouch(SeekBar seekBar) {

                    }

                    //停止拖动
                    @Override
                    public void onStopTrackingTouch(SeekBar seekBar) {
                        //将进度保存起来起来

                        //获取停止推动的进度
                        int progress = seekBar.getProgress();
                        SharedPreferences.Editor editor = sp.edit();
                        editor.putInt("progress", progress);
                        editor.commit();
                    }
                };

        }
    }


}
